/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.composite.command;

import org.eclipse.draw2d.geometry.Point;

import com.cea.papyrus.core.commands.Di2UMLElementCreateCommand;
import com.cea.papyrus.core.helper.IGraphElementHelper;
import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.diagram.composite.helper.NodePortHelper;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * 
 */
public class Di2UMLPortCreateCommand extends Di2UMLElementCreateCommand {

	/**
	 * 
	 * 
	 * @param element 
	 * @param typeDiagram 
	 * @param parent 
	 */
	public Di2UMLPortCreateCommand(Class element, GraphElement parent, String typeDiagram) {
		super(element, parent, typeDiagram);
		
	}

	/**
	 * 
	 */
	public void undo(){
		//((INodeFactory)elementFactory).deleteGraphElement(graphGe);
		((IGraphElementHelper)elementFactory).removeUMLElement(umlChild, umlParent);
		((NodePortHelper)((IGraphElementHelper)elementFactory)).undoCreateGraphElement(childGe, parentGE);
	}
	
	/**
	 * 
	 */
	public void redo(){
		//((INodeFactory)elementFactory).deleteGraphElement(graphGe);
		((IGraphElementHelper)elementFactory).addUMLElement(umlChild, umlParent);
		childGe.setSemanticParent(parentGE);
		parentGE.getContainer().getContained().add(childGe);
		//		create label
		NodeHelper nh= new NodeHelper();
		GraphElement ge= nh.createGraphElement(null, null, new Point(childGe.getPosition().x+15, childGe.getPosition().y), null);
		ge.setSemanticParent(childGe);
		ge.setContainer(parentGE.getContainer());
	}
}
